<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/19
 * Time: 22:57
 */

namespace Admin\Controller;

class FreightController extends BaseController
{

    public function add_freight()
    {
        $this->display();
    }

    public function doAddFreight()
    {
        $data['province'] = I('province');
        $data['price'] = I('price');
        $data['unit'] = I('unit');
        $data['over_price'] = I('over_price');
        $data['over_unit'] = I('over_unit');
        $data['add_time'] = time();

        foreach ($data as $k=>$v) {
            if ($v == '' || $v == null)
                echo "<script>alert('{$k},不能为空');location.replace(document.referrer);</script>";
        }

        $res = M('goods_freight')->data($data)->add();

        if ($res) {
            echo "<script>alert('操作成功');location.replace(document.referrer);</script>";
        } else {
            echo "<script>alert('操作失败');location.replace(document.referrer);</script>";
        }
    }

    public function freight_list()
    {
        $list = M('goods_freight')->select();

        $this->assign('list',$list);
        $this->display();
    }

    public function update_freight()
    {
        $maps['id'] = I('id');

        $data = M('goods_freight')->where($maps)->find();
        $this->assign('data',$data);
        $this->display();
    }

    public function doUpdateFreight()
    {
        $maps['id'] = I('id');

        $data['province'] = I('province');
        $data['price'] = I('price');
        $data['unit'] = I('unit');
        $data['over_price'] = I('over_price');
        $data['over_unit'] = I('over_unit');
        $data['add_time'] = time();

        foreach ($data as $k=>$v) {
            if ($v == '' || $v == null)
                echo "<script>alert('{$k},不能为空');location.replace(document.referrer);</script>";
        }

        $res = M('goods_freight')->data($data)->where($maps)->save();

        if ($res) {
            echo "<script>alert('操作成功');location.replace(document.referrer);</script>";
        } else {
            echo "<script>alert('操作失败');location.replace(document.referrer);</script>";
        }
    }


}